<?php

namespace app\modules\Product\models;

use Yii;

/**
 * This is the model class for table "product_group".
 *
 * @property integer $id
 * @property integer $product_id
 * @property string $name
 * @property integer $num
 * @property string $price
 * @property string $remark
 * @property integer $status
 * @property integer $user_id
 * @property string $created_at
 * @property string $updated_at
 */
class ProductGroup extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'product_group';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['product_id'], 'required'],
            [['product_id', 'num', 'status', 'user_id'], 'integer'],
            [['price'], 'number'],
            [['created_at', 'updated_at'], 'safe'],
            [['name'], 'string', 'max' => 128],
            [['remark'], 'string', 'max' => 255],
        ];
    }

     // 保存前处理
    public function beforeSave($insert) {//{{{
        if($insert){
            $this->created_at = date("Y-m-d H:i:s");
            $this->user_id    = Yii::$app->user->id;
        }
    
        return parent::beforeSave($insert);
    }//}}}

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => Yii::t('app', 'ID'),
            'product_id' => '航线',
            'name' => Yii::t('app', 'Name'),
            'num' => '数量',
            'price' => '价格',
            'remark' => '备注',
            'status' => Yii::t('app', 'Status'),
            'user_id' => Yii::t('app', 'User ID'),
            'created_at' => Yii::t('app', 'Created At'),
            'updated_at' => Yii::t('app', 'Updated At'),
        ];
    }
}
